﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Media.Animation;

namespace App10._9
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            _textAnimation = new Storyboard();
            text.TextEffects = new TextEffectCollection();

            for (int index = 0; index < text.Text.Length; index++)
            {
                TextEffect effect = new TextEffect();
                effect.Transform = new TranslateTransform();
                effect.PositionStart = index;
                effect.PositionCount = 1;
                text.TextEffects.Add(effect);

                DoubleAnimation animation = new DoubleAnimation();
                animation.To = 10;
                animation.AccelerationRatio = 0.3;
                animation.DecelerationRatio = 0.3;
                animation.AutoReverse = true;
                animation.Duration = new TimeSpan(0, 0, 0, 0, 500);
                animation.BeginTime = new TimeSpan(0, 0, 0, 0, 100 * index);

                Storyboard.SetTargetProperty(animation,
                new PropertyPath("TextEffects[" + index + "].Transform.Y"));
                Storyboard.SetTargetName(animation, text.Name);

                _textAnimation.Children.Add(animation);
            }
        }

        void OnMouseEnter(object sender, RoutedEventArgs args)
        {
            _textAnimation.Begin(this);
        }

        void OnMouseLeave(object sender, RoutedEventArgs args)
        {
            _textAnimation.Stop(this);
        }

        Storyboard _textAnimation = null;
    }
}
